/**
 * Created by caelan on 2018/10/29.
 */


var map = {
  init: function () {
    var _this = this,
        mapDom = $('#map');

    /*显示元素完成初始化*/
    mapDom.css('display', 'block');

    Global.map = new SuperMap.Map("map", {
      controls: [
        new SuperMap.Control.Navigation(),
        new SuperMap.Control.KeyboardDefaults()
      ],
//     minZoom: 4,
 //    maxZoom: 13,
 //     allOverlays : true,
  //    restrictedExtent: new SuperMap.Bounds( -179.9, -89.9, 179.9, 89.9 )
    });

    /*添加天地图底图*/
    _this.addTDT();

    /*中心区域*/
    //Global.map.zoomToExtent(Global.mapInitBounds);

    mapDom.css('display', 'none');

    /*地图选中事件*/
    //_this.selectFeature();

  },
  /*地图选中事件*/
  selectFeature: function () {
   Global.selectFeature = new SuperMap.Control.SelectCluster(Global.selectFeatureLayers, {
     callbacks : {
       //点击
       click : function(f) {
         if ( !f.info ) return;

         var template = '';

         /*基本信息*/
         if ( f.info.type === 'basic' ) {
           for ( var i in f.info.content ) {
             if ( f.info.content.hasOwnProperty(i) )
               template += '<div class="item-inline">' +
                 '<span class="item-name">'+ i +': </span>' +
                 '<span class="item-value"> '+ f.info.content[i] +'</span>' +
               '</div>';
           }
           template = '<div class="info-wrapper basic-info">'+ template +'</div>';
         }


         layLayer.close(Global.mapInfoLayer);
         Global.mapInfoLayer = layLayer.open({
           title: '信息',
           type: 1,
           shade: false,
           // btn: '确定',
           content: template
         });

       },
       //鼠标移入
       over : function(f) {
         if (f.info) {

         }
       },
       //鼠标移出
       out : function(f) {

       }
     }
   });
    /*将控件添加到地图上*/
   Global.map.addControl(Global.selectFeature);
   //激活控件。
   Global.selectFeature.activate();
 },
  /*天地图底图*/
  addTDT: function () {
    /*地形*/
//    var layer3 = new SuperMap.Layer.Tianditu();
//    layer3.layerType = "ter";
//    /*矢量图*/
//    var layer1 = new SuperMap.Layer.Tianditu();
//    layer1.layerType = "vec";
//    layer1.isLabel = false;
//    /*影像图*/
//    var layer2 = new SuperMap.Layer.Tianditu();
//    layer2.layerType = "img";
//    /*地形注记*/
//    var layer6 = new SuperMap.Layer.Tianditu();
//    layer6.layerType = "cta";
//    layer6.isLabel = true;
//    /*矢量图注记*/
//    var layer4 = new SuperMap.Layer.Tianditu();
//    layer4.layerType = "cva";
//    layer4.isLabel = true;
//    /*影像图注记*/
//    var layer5 = new SuperMap.Layer.Tianditu();
//    layer5.layerType = "cia";
//    layer5.isLabel = true;
//
//    /*添加进地图*/
//    Global.map.addLayers([layer1, layer2, layer3, layer4, layer5, layer6]);
//    /*地图顺序*/
//    Global.map.setLayerIndex(layer1, 0);
//    Global.map.setLayerIndex(layer2, 1);
//    Global.map.setLayerIndex(layer3, 2);
//    Global.map.setLayerIndex(layer4, 5);
//    Global.map.setLayerIndex(layer5, 6);
//    Global.map.setLayerIndex(layer6, 7);
//    /*显示隐藏*/
//    layer1.setVisibility(true);
//    layer2.setVisibility(false);
//    layer3.setVisibility(false);
//    layer4.setVisibility(true);
//    layer5.setVisibility(false);
//    layer6.setVisibility(false);
	  Global.layer1 = new SuperMap.Layer.TiledDynamicRESTLayer("China", Global.iserverPath, null, {maxResolution: "auto"});
	  Global.layer1.events.on({"layerInitialized": addLayer});
  }

};
function addLayer() {
    Global.map.addLayer(Global.layer1);
    //显示地图范围
    Global.map.setCenter(new SuperMap.LonLat(0, 0), 0);
}